package com.itheima.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.admin.dto.SensitivePageRequestDto;
import com.itheima.admin.mapper.AdSensitiveMapper;
import com.itheima.admin.pojo.AdSensitive;
import com.itheima.admin.service.AdSensitiveService;
import com.itheima.common.dto.PageRequestDto;
import com.itheima.common.vo.PageResultVo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class AdSensitiveServiceImpl extends ServiceImpl<AdSensitiveMapper, AdSensitive> implements AdSensitiveService {
    /**
     * 敏感词分页
     *
     * @param dto
     * @return
     */
    @Override
    public PageResultVo<AdSensitive> findPage(SensitivePageRequestDto dto) {
        //分页参数
        Page<AdSensitive> page = new Page<>(dto.getPage(), dto.getSize());
        //条件对象
        LambdaQueryWrapper<AdSensitive> lqw = new LambdaQueryWrapper<>();
        lqw.like(!StringUtils.isEmpty(dto.getName()),AdSensitive::getSensitives,dto.getName());
        page(page,lqw);

        PageResultVo<AdSensitive> result = PageResultVo.pageResult(page.getCurrent(), page.getSize(), page.getTotal(), page.getRecords());
        return result;
    }
}
